Public Class DefaultError
    Inherits System.Web.UI.Page
    Protected WithEvents lblError As System.Web.UI.WebControls.Label
    Protected Const ErrorConfigString As String = "MIMS_WRS.ErrorPage.Level"
    Protected Const ErrorMessageString As String = "An error occur! Please contact your system administrator."

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim myError As Exception = Server.GetLastError.InnerException

        Dim errorLevel As Integer

        Try
            errorLevel = CInt(System.Configuration.ConfigurationSettings.AppSettings(ErrorConfigString))
        Catch ex As Exception
            errorLevel = -1
        End Try

        Select Case errorLevel
            Case -1
                Do
                    Try
                        lblError.Text &= "<u>Exception:</u>&nbsp;" & myError.Message & "<BR>"
                        lblError.Text &= "<u>Occurs</u>&nbsp;" & myError.StackTrace & "<BR><BR>"
                        myError = myError.InnerException
                    Catch ex As Exception
                        Exit Do
                    End Try
                Loop
            Case 0
                lblError.Text = ErrorMessageString
            Case Is > 0
                Dim i As Integer
                For i = 1 To errorLevel
                    Try
                        lblError.Text &= myError.Message & "<BR>"
                        myError = myError.InnerException
                    Catch ex As Exception
                        Exit For
                    End Try
                Next
        End Select
        Server.ClearError()
    End Sub
End Class
